package com.potenza.training.reply.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.potenza.training.reply.dao.ReplySubjectRecordDao;
import com.potenza.training.reply.entity.ReplySubjectRecordEntity;
import com.potenza.training.reply.service.ReplySubjectRecordService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.Map;


@Service("replySubjectRecordService")
public class ReplySubjectRecordServiceImpl extends ServiceImpl<ReplySubjectRecordDao, ReplySubjectRecordEntity> implements ReplySubjectRecordService {

    @Resource
    private ReplySubjectRecordDao replySubjectRecordDao;

    @Override
    public Page<ReplySubjectRecordEntity> queryPage(Map map, Integer page, Integer size) {
        QueryWrapper<ReplySubjectRecordEntity> replyGroupEntityQueryWrapper = new QueryWrapper<>();
        Object key = map.get("key");
        if(!StringUtils.isEmpty(key)){
            Long keyData = Long.parseLong(String.valueOf(key));
            replyGroupEntityQueryWrapper.lambda().eq(ReplySubjectRecordEntity::getHomeId,keyData);
        }
        Page<ReplySubjectRecordEntity> pageData = new Page<>();
        pageData.setSize(size);
        pageData.setCurrent(page);

        return replySubjectRecordDao.selectPage(pageData,replyGroupEntityQueryWrapper);
    }
}